from rest_framework import serializers
from .models import *

class OrderInfoSer(serializers.ModelSerializer):
    user_name = serializers.SerializerMethodField(read_only=True)
    # 获取用户名
    def get_user_name(self,obj):
        return obj.user.username

    status_name = serializers.SerializerMethodField(read_only=True)
    # 获取支付状态的字符串信息(如：待支付)
    def get_status_name(self,obj):
        return obj.get_status_display()

    class Meta:
        model = OrderInfo
        fields = '__all__'
        read_only_fields = ['order_id',]

class OrderGoodsSer(serializers.ModelSerializer):
    class Meta:
        model = OrderGoods
        fields = '__all__'
        read_only_fields = ['id',]